var prefix = "/sys/user";
layui.use(['form', 'util'], function(){
	var form = layui.form;
	var layer = layui.layer;
	//自定义验证规则
	form.verify({
		username: function (val){
			if( !val.length ){
				return '请输入姓名';
			}
			console.log(val);
		},
		mobile: function(value){
			if(value.length < 11){
				return '号码不能小于11位数';
			}
			const telStr = /^[1](([3][0-9])|([4][0,1,4-9])|([5][0-3,5-9])|([6][2,5,6,7])|([7][0-8])|([8][0-9])|([9][0-3,5-9]))[0-9]{8}$/;
			if (!(telStr.test(value))) {
				return "手机号码输入不规范";
			}

		},
	});

	//提交事件
	form.on('submit(submit)', function(data){
		data.field.type = 0; // 用户类型
		$.ajax({
			url : prefix+"/save",
			type : "post",
			data : data.field,
			success : function(r) {
				if (r.code == 0) {
					parent.layer.msg("操作成功");
					parent.load();
					var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
					parent.layer.close(index);
				} else {
					layer.msg(r.msg);
				}
			}
		});
		return false;
	});

});